var util = require('../../utils/util.js');
var uid = 0;
var app = getApp();
var albumid = 0;
var cpage = 1;
var hasMore = true;
var goonMore = false;
Page({
  data: {
      result:[],
      imgDomain: app.globalData.imgDomain
  },
  goAtherPage: function(e){
      var url = e.currentTarget.dataset.link;
      wx.navigateTo({url: url})
  },
  loadMore:function(){
      if(hasMore && goonMore){
        goonMore = false;
        cpage ++;
        this.load(cpage);
      }
  },
  onLoad: function(data){
    uid = data.uid || "";
    albumid = data.albumid || "";
    //初始化值
    cpage = 1;
    hasMore = true;
    this.load(cpage);
  },
  load:function(cpage){
    var that = this;
    util.api({
        data:{
            publickey:util.publiccode,
            ac:"topiclist",
            postuid:uid,
            topictype:6,
            toporder:1,
            albumid:albumid,
            page:cpage,
            num:20
        },
        success:function(responseData){
            var result = responseData.data;
            if(result && result.length > 0){
                result.forEach(function(m,i){
                if(m.photos)
                    result[i].photosData = m.photos.split(",");
                });
                that.setData({
                    result:that.data.result.concat(result)
                });
            }else{
                hasMore = false;
            }
            goonMore = true;
        }
    });
  }
})